#include"../../server/rpc_server.hpp"
#include"../../common/detail.hpp"

void Add(const Json::Value & prams, Json::Value& result)
{
    int num1 =prams["num1"].asInt();
    int num2 =prams["num2"].asInt();
    result=num1+num2;
    DLOG("服务端本次的Add收到的参数为: %d", num1);
    DLOG("服务端本次的Add收到的参数为: %d", num2);

    DLOG("服务端本次的计算结果为: %d",result.asInt());

}

int main()
{
    //实例化工厂对象
    std::unique_ptr<RPC_project::server::SDescribeFactory> desc_factory = std::make_unique<RPC_project::server::SDescribeFactory>();
    desc_factory->setMethodName("Add");
    desc_factory->setParamsDesc("num1" ,RPC_project::server::VType::INTEGRAL);
    desc_factory->setParamsDesc("num2" ,RPC_project::server::VType::INTEGRAL);
    desc_factory->setReturnType(RPC_project::server::VType::INTEGRAL);
    desc_factory->setCallback(Add);

    RPC_project::server::RpcServer server(RPC_project::Address("127.0.0.1" ,9090));
    server.registerMethod(desc_factory->build());
    server.start();



    return 0;
}